local sk__dingguan = fk.CreateSkill {

  name = "sk__dingguan",

  tags = {},

}



sk__dingguan:addEffect(fk.TargetSpecified, {
  name = "sk__dingguan",
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(sk__dingguan.name) and target.phase == Player.Play and data.firstTarget and
        data.card.color == Card.Black and
        table.find(data:getAllTargets(), function(p)
          return not p.dead
        end) and #player.room.logic:getActualDamageEvents(1, Util.TrueFunc, Player.HistoryPhase) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.filter(data:getAllTargets(), function(p)
      return not p.dead
    end)
    local tos = player.room:askForChoosePlayers(player, targets, 1, 999, "#sk__dingguan-choose", sk__dingguan.name, true)
    if #tos > 0 then
      event:setCostData(self, tos)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:sortByAction(table.map(event:getCostData(self), Util.Id2PlayerMapper))
    for _, id in ipairs(event:getCostData(self)) do
      local p = room:getPlayerById(id)
      if not p.dead then
        p:drawCards(1, sk__dingguan.name)
      end
    end
  end,
})

return sk__dingguan
